package com.oil.petro.eshop.entity;

import com.oil.petro.eshop.bean.ProductBean;
import com.oil.petro.eshop.bean.UserBean;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name = "account")
public class Account implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    int id;
    @Column(name = "login")
    String login;
    @Column(name = "password")
    String password;
    @Column(name = "email")
    String email;
    @Column(name = "person_id")
    int personId;
    @Column(name = "role")
    String role;

//    @ManyToMany(cascade = CascadeType.PERSIST)
//    @JoinTable(name = "cart", joinColumns = {
//        @JoinColumn(name = "account_id")},
//            inverseJoinColumns = {
//                @JoinColumn(name = "product_id")})
//    private Set<Product> products = new HashSet<Product>();

    
//     @OneToMany(mappedBy = "account")
//     @LazyCollection(LazyCollectionOption.FALSE)
//    private Set<Cart> cart = new HashSet<Cart>();
    
//     @Transient
//      @OneToMany( mappedBy = "pk.account")
//                @LazyCollection(LazyCollectionOption.FALSE)
//Set<AccountProduct> accountProduct = new HashSet<AccountProduct>();
//
//    public Set<AccountProduct> getAccountProduct() {
//        return accountProduct;
//    }
//
//    public void setAccountProduct(Set<AccountProduct> accountProduct) {
//        this.accountProduct = accountProduct;
//    }

   
     
    public Account() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getPersonId() {
        return personId;
    }

    public void setPersonId(int personId) {
        this.personId = personId;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public Account(String login, String password, String email, int person_id) {
        this.login = login;
        this.password = password;
        this.email = email;
        this.personId = personId;
    }

    public Account(UserBean userBean) {
        this.login = userBean.getLogin();
        this.password = userBean.getPassword();
        this.email = userBean.getEmail();
    }

//    public Set<Product> getProducts() {
//        return products;
//    }
//
//    public void addProduct(Product product,ProductBean productBean) {
//
////        if (products.contains(product)) {
////
////        } else {
//
//     
//        
//            products.add(product);
//        //}
//    }
//    
//     public void setProducts(Set<Product> products) {
//        this.products = products;
//    }


//    public Set<Cart> getCart() {
//        return cart;
//    }
//
//    public void setCart(Set<Cart> cart) {
//        this.cart = cart;
//    }
//
//     public void addCart(Cart cart,ProductBean productBean,Set<Cart> carts) {
//         
//         
////         
////             if(this.cart.contains(productBean)){
////        System.out.println("AAAAAAAAAAAAAAAAAAQQQQSSSQQ");
////        
////         cart.setOrderedQuantity(productBean.getOrderedQuantity());
////        
////        }
////                   if(carts.contains(cart)){
////        System.out.println("AAAAAAAAAAAAAAAAAAQQQQQQ");
////        cart.setOrderedQuantity(productBean.getOrderedQuantity());
////         for(Cart item:carts){
////        if(item.equals(cart)){
////        cart.setOrderedQuantity(item.getOrderedQuantity()+cart.getOrderedQuantity());
////            
////            carts.remove(item);
////            this.cart.add(cart);
////                System.out.println("BBBBBBBBBBBBBBB");
////
////        }
////        
////        }
////        }else 
//        this.cart.add(cart);
//    }

    
   
}
